﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using AMM.Business.Business;
using AMM.CustomClassLibrary;
using AMM.Model.Business;

namespace AMM {
    public partial class FrmTest : Form {
        public FrmTest() {
            InitializeComponent();

            //this.dataGridView1.AutoGenerateColumns = true;
            //this.BindCustomer(0);
        }

        private void BindCustomer(int produceConductId) {
            int pagesize = 20;
            CustomerSearchModel searchModel = new CustomerSearchModel() { IsEnabled = true };
            CustomerProcessor customerProcessor = new CustomerProcessor(20);
            List<CustomerViewModel> customerList = customerProcessor.FetchCustomerViewModelList(searchModel);

            //if (produceConductId == 0) {
            //    CustomerSearchModel searchModel = new CustomerSearchModel() { IsEnabled = true };
            //    customerList = customerProcessor.FetchCustomerViewModelList(searchModel);
            //}
            //else {
            //    customerList = customerProcessor.FetchCustomerViewModelListByProcumentOrderId(produceConductId);
            //}

            this.Customer.DataGridViewSourceEx = customerList;
            this.Customer.DisplayMemberEx = "Code";
            this.Customer.ValueMemberEx = "Key";
            this.Customer.RowsEx = searchModel.Records;
            //this.Customer.HeightEx = 300;
            //this.Customer.WidthEx = 150;
            this.Customer.PageSizeEx = pagesize;
            this.Customer.Search += (s, e) => {
                searchModel.Code = e.SearchText;
                customerList = customerProcessor.FetchCustomerViewModelList(searchModel, e.PageIndex);
                this.Customer.DataGridViewSourceEx = customerList;
                this.Customer.RowsEx = searchModel.Records;
            };
            this.Customer.DataBind(new CustomerViewModel(), x => new { x.Code, x.Name, x.Linkman1 });
        }

        private void FrmTest_Load(object sender, EventArgs e) {
            this.textBox1.Text = SecurityHelper.DESEncrypt(this.label1.Text);
            this.textBox2.Text = SecurityHelper.DESEncrypt(this.label2.Text);

            this.BindCustomer(0);

            ControlPaint.DrawReversibleFrame(new Rectangle(10, 10, 100, 100), SystemColors.ControlText, FrameStyle.Dashed);

        }

        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);

            ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(100, 100, 100, 100));
        }

        private void button1_Click(object sender, EventArgs e) {
            var a = this.dateTimePicker1.Checked;
            var b = this.dateTimePicker1.Value;
        }

        private void dataGridView1_ControlAdded(object sender, ControlEventArgs e) {

        }

    }
}
